home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / R / RequiredAE XCMD ƒ / source / aeCAvail.c next >
Encoding:
C/C++ Source or Header  |  1991-08-11  |  2.5 KB  |  138 lines  |  [TEXT/KAHL]

  1. /***
  2.  * aeCAvail.c
  3.  *
  4.  *  This XFCN will take two parameters (assumed to be 4 character strings)
  5.  *  and try and see if there is a coer. handler between the two.
  6.  *
  7.  *  Gordon Watts July '91 Copyright.
  8.  *
  9.  ***/
  10. #include    <HyperXCmd.h>
  11.  
  12. #define versionString (StringPtr) "\pAECAvailable v1.0 Gordon Watts Aug 1991"
  13. #define usageString (StringPtr) "\pAECAvailable <from-type> <to-type> \
  14. <isSystem|needDesc|refCon|procPtr|theError>"
  15. #define badParamStr (StringPtr) "\pUse arg ? for usage."
  16.  
  17. /**
  18.  * main 
  19.  *
  20.  *  Main routine for this xfunction.
  21.  *
  22.  **/
  23. pascal void main(XCmdPtr paramPtr)
  24. {
  25.     Str255 theString;
  26.     OSErr theErr;
  27.     ProcPtr theHandler;
  28.     long refCon;
  29.     Boolean typeIsDesc, isSysHandler;
  30.     OSType *fromType, *toType;
  31.     
  32.     /**
  33.      ** See if we have only one parameter... if it is one of the
  34.      ** ! or ?, return the string...
  35.      **/
  36.     
  37.         if (paramPtr -> paramCount == 1) {
  38.     
  39.         switch (**(paramPtr -> params[0])) {
  40.         
  41.             case '!':
  42.                 paramPtr -> returnValue =
  43.                     PasToZero (paramPtr, versionString);
  44.                 return;
  45.                 break;
  46.             
  47.             case '?':
  48.                 paramPtr -> returnValue =
  49.                     PasToZero (paramPtr, usageString);
  50.                 return;
  51.                 break;
  52.             
  53.         }
  54.     }
  55.  
  56.     /**
  57.      ** Right, make sure we have three parameters...
  58.      **/
  59.     
  60.     if (paramPtr -> paramCount != 3) {
  61.         paramPtr -> returnValue = PasToZero (paramPtr, badParamStr);
  62.         return;
  63.     }
  64.  
  65.     /**
  66.      ** Get the from type and the to type.
  67.      **/
  68.  
  69.     fromType = (OSType*) *(paramPtr -> params[0]);
  70.     toType = (OSType*) *(paramPtr -> params[1]);
  71.  
  72.     /**
  73.      ** Init all the stuff...
  74.      **/
  75.  
  76.     theHandler = 0;
  77.     refCon = 0;
  78.  
  79.     /**
  80.      ** Check to see if this is app defined...
  81.      **/
  82.  
  83.     isSysHandler = false;
  84.     theErr = AEGetCoercionHandler (*fromType, *toType, &theHandler,
  85.                                 &refCon,
  86.                                 &typeIsDesc, false);
  87.  
  88.  
  89.     /**
  90.      ** Next, if it isn't app defined, see if it is system
  91.      ** defined...
  92.      **/
  93.     
  94.     if (theErr != noErr) {
  95.     
  96.         isSysHandler = true;
  97.         theErr = AEGetCoercionHandler (*fromType, *toType, &theHandler,
  98.                                 &refCon,
  99.                                 &typeIsDesc, true);
  100.  
  101.     }
  102.  
  103.     /**
  104.      ** Next, pull out the proper info...
  105.      **/
  106.     
  107.     switch (**(paramPtr -> params[2])) {
  108.     
  109.         case 'i':
  110.             BoolToStr (paramPtr, isSysHandler, theString);
  111.             break;
  112.  
  113.         case 'n':
  114.             BoolToStr (paramPtr, typeIsDesc, theString);
  115.             break;
  116.  
  117.         case 'r':
  118.             NumToHex (paramPtr, refCon, 8, theString);
  119.             break;
  120.  
  121.         case 'p':
  122.             NumToHex (paramPtr, (long) theHandler, 8, theString);
  123.             break;
  124.  
  125.         case 't':
  126.             NumToStr (paramPtr, theErr, theString);
  127.             break;
  128.  
  129.         default:
  130.             paramPtr -> returnValue = PasToZero (paramPtr, badParamStr);
  131.             return;
  132.             break;
  133.     }
  134.     
  135.     paramPtr -> returnValue = PasToZero (paramPtr, theString);
  136.     return;
  137. }
  138.